#include <Arduino.h>
#include "WiFiManager.h"
#include "TimeManager.h"
#include "TCPManager.h"
#include "DisplayManager.h"
#include "WebConfigManager.h"
#include "App.h"

void inkSetup()
{
    Serial.begin(115200);
    WiFiManagerModule::setupWiFi();
    WebConfigManager::startServer();
    TimeManager::syncTime();
    // DisplayManager::initDisplay();
    TCPManager::fetchData();
    DisplayManager::updateDisplayFull();
    // 任务完成 -> 断电省电
    DisplayManager::sleep();
    WiFi.disconnect(true);
    WiFi.mode(WIFI_OFF);

    esp_sleep_enable_timer_wakeup(UPDATE_INTERVAL_US);
    Serial.println("进入深度睡眠...");
    esp_deep_sleep_start();
}

void inkLoop()
{
    // static unsigned long lastUpdate = 0;
    // if (millis() - lastUpdate > DisplayManager::UPDATE_INTERVAL_MS) {
    //     lastUpdate = millis();
    //     if (WiFi.status() != WL_CONNECTED) WiFi.reconnect();
    //     TimeManager::syncTime();
    //     TCPManager::fetchData();
    //     DisplayManager::updateDisplayFull();
    //       // 节电措施
    //     WiFi.disconnect(true);
    //     WiFi.mode(WIFI_OFF);
    //     DisplayManager::sleep(); // 让墨水屏待机
    // }
    // delay(1000);
}